package com.lijing.BubbleSort;

public class Bubble {
    public static void sort(Comparable[] arr){
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (greater(arr[j],arr[j+1])){
                    exch(arr,j,j+1);
                }
            }
        }
    }
    private static boolean greater(Comparable v, Comparable w){
        return v.compareTo(w) > 0;
    }

    private static void exch(Comparable[] a, int i, int j){
        Comparable temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
